package com.toune.dltools.dialog.form

import android.content.Context
import android.view.View
import com.tamsiree.rxkit.view.RxToast
import com.toune.dltools.DLBaseDialog
import com.toune.dltools.R
import com.toune.dltools.bean.DLCreateFormBean
import kotlinx.android.synthetic.main.dialog_create_form.view.*

class SingleInputFormDialog(
    context: Context?,
    layoutId: Int,
    tag: String,
    formCallBack: FormCallBack
) :
    DLBaseDialog(context, layoutId) {
    private val formCallBack = formCallBack
    private val tag = tag

    init {
        when (tag) {
            DLCreateFormBean.TEXT.toString(), DLCreateFormBean.SWITCH.toString() -> {
                dialogView!!.hintLv.visibility = View.GONE
            }
            DLCreateFormBean.DATE.toString() -> {
                dialogView!!.hintLv.visibility = View.GONE
                dialogView!!.dateLv.visibility = View.VISIBLE
            }
            else -> {
                dialogView!!.hintLv.visibility = View.VISIBLE
            }
        }
    }

    override fun initEvent() {
        dialogView!!.submitBtn.setOnClickListener {
            if (dialogView!!.nameEt.text!!.isBlank()) {
                RxToast.info("输入名称")
                return@setOnClickListener
            }
            if (dialogView!!.hintLv.visibility == View.VISIBLE && dialogView!!.placeHolderEt.text!!.isBlank()) {
                RxToast.info("输入提示语")
                return@setOnClickListener
            }
            val dlCreateFormBean = DLCreateFormBean()
            dlCreateFormBean.tag = tag.toInt()
            dlCreateFormBean.params =
                arrayListOf(
                    dialogView!!.nameEt.text.toString(),
                    dialogView!!.placeHolderEt.text.toString()
                )
            formCallBack?.onCallBack(dlCreateFormBean)
            dismiss()
        }
    }
}